package com.example.hp.service.impl;

import com.example.hp.entity.Students;
import com.example.hp.dao.StudentsDao;
import com.example.hp.service.StudentsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (Students)表服务实现类
 *
 * @author makejava
 * @since 2024-12-15 16:49:54
 */
@Service("studentsService")
public class StudentsServiceImpl implements StudentsService {
    @Resource
    private StudentsDao studentsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param studentId 主键
     * @return 实例对象
     */
    @Override
    public Students queryById(Integer studentId) {
        return this.studentsDao.queryById(studentId);
    }

    /**
     * 分页查询
     *
     * @param students 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Students> queryByPage(Students students, PageRequest pageRequest) {
        long total = this.studentsDao.count(students);
        return new PageImpl<>(this.studentsDao.queryAllByLimit(students, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param students 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Students students) {
        int insert = studentsDao.insert(students);
        return insert;
    }

    /**
     * 修改数据
     *
     * @param students 实例对象
     * @return 实例对象
     */
    @Override
    public Students update(Students students) {
        this.studentsDao.update(students);
        return this.queryById(students.getStudentId());
    }

    /**
     * 通过主键删除数据
     *
     * @param studentId 主键
     * @return 是否成功
     */
    @Override
    public Boolean deleteById(Integer studentId) {
        return studentsDao.deleteById(studentId) ;
    }
}
